﻿<?php

// no direct access
defined('_JEXEC') or die('Restricted access');

jimport( 'joomla.application.component.view');
jimport( 'joomla.document.feed.feed' );

require_once JPATH_COMPONENT.DS.'/helpers/functions.check.php';

/**
 * HTML View class for the eventcalendar component
 * 
 * TÄMÄ EI TOIMI
 *
 */
class EventcalendarViewGeorss extends JView {
	function display($tpl = null) {

		//Todo: johonkin järkevämpään paikkaan
		$default_limit = 10;
	

		$alkuaika = JRequest::getVar( 'alkuaika' );
				
		if($alkuaika == null)
		{			
			date_default_timezone_set('Europe/Helsinki');
			$alkuaika = date('d.m.Y');
		}
		
		//Monta haetaan
		$limit = JRequest::getVar( 'limit' );

		//Oma model
		$model = &$this->getModel();
		if(intval($limit) > 0)
		{
			$events = $model->getEvents($alkuaika, $limit);
		}
		else 
		{
			$events = $model->getEvents($alkuaika, $default_limit);
		}
		
		$doc = &JFactory::getDocument();
		
		foreach ($events as $event)
		{
			// strip html from feed item nimi
			$title = $this->escape($event->nimi);
			$title = html_entity_decode($title, ENT_COMPAT, 'UTF-8');
			
			//Miten saadaan linkki?
			//$link =
			
			// load individual item creator class
			$item = new JFeedItem();
			$item->title			= $title;
			//$item->link		= $link;
			$item->description		= $description;
			//$item->date		= $date;
			//$item->category	= $row->category;

			// loads item info into rss array
			$doc->addItem($item);

		}
		

		//$events =& $this->get('events');	
		//$this->assignRef('events',$events);
		//parent::display($tpl);
	}

	
}
?>
